set the highlight of background button "Other salt" to false
set the highlight of background button "KCl" to false
set the highlight of background button "NaCl" to true
set the highlight of background button "Na2SO4" to false
end mouseUp
-- part 17 (button)
-- low flags: 00
-- high flags: A006
-- rect: left=339 top=121 right=142 bottom=382
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: KCl
----- HyperTalk script -----
on mouseUp
set the highlight of background button "Other salt" to false
set the highlight of background button "KCl" to true
set the highlight of background button "NaCl" to false
set the highlight of background button "Na2SO4" to false
end mouseUp
-- part 18 (button)
-- low flags: 00
-- high flags: 2006
-- rect: left=391 top=121 right=142 bottom=462
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Na2SO4
----- HyperTalk script -----
on mouseUp
set the highlight of background button "Other salt" to false
set the highlight of background button "KCl" to false
set the highlight of background button "NaCl" to false
set the highlight of background button "Na2SO4" to true
end mouseUp
-- part 31 (field)
-- low flags: 81
-- high flags: 2007
-- rect: left=349 top=249 right=280 bottom=473
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 22
-- text size: 10
-- style flags: 0
-- line height: 13
-- part name: DH
-- part 30 (field)
-- low flags: 01
-- high flags: 0002
-- rect: left=13 top=182 right=289 bottom=261
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 3
-- text size: 9
-- style flags: 0
-- line height: 12
-- part name: BufferInfo
-- part 36 (button)
-- low flags: 00
-- high flags: 6005
-- rect: left=17 top=145 right=160 bottom=33
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: FreeI
----- HyperTalk script -----
on mouseUp
set the highlight of background button "FreeI" to true
set the highlight of background button "FixI" to false
put empty into field "I"
set the highlight of background button "KCl" to false
set the highlight of background button "NaCl" to false
set the highlight of background button "Na2SO4" to false
set the highlight of background button "Other salt" to false
end mouseUp
-- part 37 (button)
-- low flags: 00
-- high flags: 2005
-- rect: left=17 top=124 right=140 bottom=34
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: FixI
----- HyperTalk script -----
on mouseUp
set the highlight of background button "FreeI" to false
set the highlight of background button "FixI" to true
end mouseUp
-- part 43 (field)
-- low flags: 00
-- high flags: 2002
-- rect: left=396 top=86 right=106 bottom=446
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 21
-- text size: 12
-- style flags: 0
-- line height: 12
-- part name: Volume
-- part 44 (button)
-- low flags: 00
-- high flags: A003
-- rect: left=272 top=295 right=316 bottom=372
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Edit buffers
----- HyperTalk script -----
on mouseUp
ask password "Enter password to edit buffers"
if it <> 3246591934 then
exit mouseUp
else
answer "What editing ?" with "New" or "Edit" or "Done"
if it is "New" then
put the script of this card into tempscript
domenu new card
put "(Name of buffer)" & return after field BufferInfo
put "pKa is ??.??" & return after field BufferInfo
put "dpK/dT is ????" & return after field BufferInfo
put "charge on acid species is ??" & return after field BufferInfo
put "made from ????????????" & return after field BufferInfo
put "Mol.wt. is ???.??" & return after field BufferInfo
put "Shortname is ?????" & return after field BufferInfo
put "Notes: (free format-1 line max)" & return after field BufferInfo
set the script of this card to tempscript
set the lockText of background field "BufferInfo" to false
else
if it is "Edit" then
set the lockText of background field "BufferInfo" to false
else
if it is "Done" then set the lockText of background field "BufferInfo" to true
put line 1 of field BufferInfo into field Name
end if
end if
end if
end mouseUp
-- part 46 (button)
-- low flags: 00
-- high flags: 2001
-- rect: left=10 top=292 right=320 bottom=40
-- title width / last selected line: 0
-- icon id / first selected line: 9301 / 9301
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Previous
----- HyperTalk script -----
on mouseUp
visual effect dissolve
go to previous card
end mouseUp
-- part 48 (button)
-- low flags: 00
-- high flags: 2001
-- rect: left=458 top=294 right=320 bottom=491
-- title width / last selected line: 0
-- icon id / first selected line: 27009 / 27009
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Next
----- HyperTalk script -----
on mouseUp
put the number of this card into n
put the number of cards into s
if n=s then
beep
else
visual effect dissolve
go to next card
end if
end mouseUp
-- part 22 (button)
-- low flags: 00
-- high flags: A003
-- rect: left=377 top=295 right=316 bottom=445
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Recipe
----- HyperTalk script -----
function DebyeHuckel T
-- use a second order polynomial to approximate (*very* closely)
-- the Debye Hückel parameter at any temperature
put (0.4918 + 0.0006614*T + 0.000004975*T^2) into DH
return DH
end DebyeHuckel
function CalculateI pH,pK,z,Conc
--
-- calculate the ionic strength due to all buffer species
-- N.B. assumes that all counterions are monovalent
-- e.g. Na+,K+,Cl-
-- z = charge on acid species
-- Conc = total concentration of all buffer species
-- I = ionic strength due to buffer species
--
put 10^(pH-pK) into R
put (R/(1+R) * Conc * (z-1)^2) into I1 -- basic species
put (1/(1+R) * Conc * z^2) into I2 -- acidic species
put (R/(1+R) * Conc * abs(z-1)) into I3 -- counterion to basic species
put (1/(1+R) * Conc * abs(z)) into I4 -- counterion, acidic species
put (I1 + I2 + I3 + I4)/2 into I
return I
end CalculateI
function CalculateNewpKa pK,I,T,z
-- calculates the pKa' from pKa according to
-- Debye-Hückel modifications
-- T = temperature in centigrade
put DebyeHuckel(T) into A
put A * sqrt(I) into corr
--
-- this is anternative formula sometimes used
-- replacing next three lines
-- put corr * (-2*z+1) into corr1
-- put corr1/(1+1.6*sqrt(I)) into corr1
--
put corr/(1 + sqrt(I)) into corr1
put corr1 - (0.1 * I) into corr1
put corr1 * (2*z - 1) into corr1
--
put pK + corr1 into P
return P
end CalculateNewpKa
on mouseUp
-- range checking - valid buffer requested?
if background field "T" is empty then
ask "At what temperature will you use the buffer ?" with "37.4"
put it into background field "T"
end if
if background field "LabT" is empty then put 20 into background field "LabT"
if background field "Volume" is empty then put 1000 into background field "Volume"
if background field "pH" is empty then
ask "What pH will the buffer be ?"
put it into background field "pH"
if it is empty then exit mouseUp
end if
if background field "Conc" is empty then
ask "What buffer concentration (M) ?"
put it into background field "Conc"
if it is empty then exit mouseUp
end if
if background field "I" is empty then
put "FreeI" into BufferType
set the highlight of background button "FreeI" to true
set the highlight of background button "FixI" to false
else
put "NoFreeI" into BufferType
set the highlight of background button "FreeI" to false
set the highlight of background button "FixI" to true
end if
-- get the current buffer parameters
put background field "pH" into pH
put background field "T" into T
put background field "Conc" into C
put background field "I" into I
put background field "Volume" into V
put background field "LabT" into LabT
-- get the current buffer properties
-- there is no syntax checking - so care with buffer details!
-- get buffer name
put line 1 of field "BufferInfo" into BufferName
-- get thermodynamic pKa
put word 3 of line 2 of field "BufferInfo" into pKa
-- get temperature coefficient
put word 3 of line 3 of field "BufferInfo" into dpKadT
-- get charge on acidic species (for this ionisation)
put word 6 of line 4 of field "BufferInfo" into za
-- get the material used to make buffer
put word 3 of line 5 of field "BufferInfo" into BufferStuff
-- get the molecuar weight of same
put word 3 of line 6 of field "BufferInfo" into MW
-- get a short name for convenience
put word 3 of line 7 of field "BufferInfo" into ShortName
-- get any notes appended to bufer
put line 8 of field "BufferInfo" into Notes
-- range check Conc, I, pH and T requested
-- (checks conducted before pKa - > pK', though)
if abs (pH-pKa) > 1.0 then
answer "This buffer is not appropriate, pKa=" && pKa
exit mouseUp
else
if abs (pH-pKa) > 0.8 then
answer "This buffer is only just OK, pKa=" && pKa with "Go ahead"
if it is "Cancel" then exit MouseUp
end if
end if
if (T<0 or T>60) then
answer T && "°C is outside the useable range of 0-60°C"
exit MouseUp
end if
if BufferType is "FreeI" then
set the highlight of background button "KCl" to false
set the highlight of background button "NaCl" to false
set the highlight of background button "Na2SO4" to false
set the highlight of background button "Other salt" to false
end if
put empty into field "v"
show field "v"
hide background button "Recipe"
show background button "OK"
hide background button "Help!"
hide background button "Tutorial"
show background button "Save to disk"
show background button "Edit buffers"
set numberFormat to 0.000
-- now have all parameters set up
-- modify pKa for temperature
put (pKa + dpKadT*(T-25)) into pKaPrime
if BufferType is "FreeI" then
-- here if we don't want to control ionic strength
put pkaPrime into pK1
put 1000 into diff -- a big number
set cursor to busy
repeat until diff < 0.001
set cursor to busy
put CalculateI(pH,pK1,za,C) into I
put CalculateNewpKa(pKaPrime,I,T,za) into pK2
put abs (pK1 - pK2) into diff
put pK2 into pK1
end repeat
-- pKa is original pK value (thermodynamic)
-- pKaPrime is the temperature corrected pKa
-- pK2 is the ionic strength corrected value
-- I is the ionic stength
-- how much buffer stuff ?
put C * MW * V/1000 into Weight
-- work out pH at lab temperature (approx)
put (pK2 + dpKadT*(LabT-T)) into LabpKa
put 10^(pH-pK2) into R
put LabpKa + ln(R)/2.3 into LabpH
-- ready for recipe
put "Buffer recipe " & the long date & return into field "v"
put return after field "v"
put "Buffer : " & C & "M " & BufferName & " pH " & pH & " at T=" & T & " °C" & return after field "v"
put " pH: " & LabpH & " at lab temperature of " & LabT & " °C" & return after field "v"
put return after field "v"
put " T: " & T & "°C" & return after field "v"
put " pKa: " & pKa & ", pKa': " & pK2 & " (dpKa/dT: " & dpKadT & ")" & return after field "v"
put " I: " & I & " (Ionic strength due to buffer components)" & return after field "v"
put " " & Notes & return after field "v"
put return after field "v"
put "1. Dissolve " & Weight & "g " & BufferStuff & return after field "v"
put " in ~" & V*0.8 & " ml double distilled water." & return & return after field "v"
put "2. Titrate to pH " & LabpH & " with monobasic acid or alkali." & return & return after field "v"
put "3. Make up to " & V & "mls" & return after field "v"
put "" & return after field "v"
else
-- here if we do control ionic strength
-- I is the specified ionic strength
put empty into field "v"
if (the highlight of background button "KCl" is false and the highlight of background button "NaCl" is false and the highlight of background button "Na2SO4" is false and the highlight of background button "Other salt" is false) then
set the highlight of background button "NaCl" to true
end if
if the highlight of background button "Other salt" is true then
put "other salt" into SaltName
put 74.56 into SaltMW -- these are dummy parameters
put 1 into SaltF -- so is this
end if
if the highlight of background button "KCl" is true then
put "KCl" into SaltName
put 74.56 into SaltMW
put 1 into SaltF
end if
if the highlight of background button "NaCl" is true then
put "NaCl" into SaltName
put 58.44 into SaltMW
put 1 into SaltF
end if
if the highlight of background button "Na2SO4" is true then
put "Na2SO4" into SaltName
put 142.04 into SaltMW
put 3 into SaltF
end if
put CalculateNewpKa(pKaPrime,I,T,za) into pK2
put calculateI(pH,pk2,za,C) into Icalc
if Icalc > I then
answer "Calculated I of this buffer is too large I!"
exit MouseUp
else
put C * MW * V/1000 into Weight
-- work out pH at lab temperature (approx)
put (pK2 + dpKadT*(LabT-T)) into LabpKa
put 10^(pH-pK2) into R
put LabpKa + ln(R)/2.3 into LabpH
put (I-Icalc) into saltI
put (saltI/SaltF) into SaltM
put SaltM * SaltMW * V/1000 into SaltWeight
put "Buffer recipe " & the long date & return into field "v"
put return after field "v"
put "Buffer : " & C & "M " & BufferName & " pH " & pH & " at T=" & T & " °C" & return after field "v"
put " pH: " & LabpH & " at lab temperature of " & LabT & " °C" & return after field "v"
put return after field "v"
put return after field "v"
put " pH: " & pH & return after field "v"
put " T: " & T & "°C" & return after field "v"
put " pKa: " & pKa & ", pKa': " & pK2 & " (dpKa/dT: " & dpKadT & ")" & return after field "v"
if the highlight of background button "Other salt" is false then
put " I: " & I & " (Maintained with " & SaltM & "M " & SaltName & " to I= " & saltI & ")" & return after field "v"
else
put " I: " & I & " (Maintained with " & SaltName & " to I= " & saltI & ")" & return after field "v"
end if
put " " & Notes & return after field "v"
put return after field "v"
if the highlight of background button "Other salt" is true then
put "1. Dissolve " & Weight & "g " & BufferStuff & return after field "v"
put " and a salt to I= " & saltI & return after field "v"
put " in ~" & V*0.8 & " ml double distilled water." & return & return after field "v"
else
put "1. Dissolve " & Weight & "g " & BufferStuff & return after field "v"
put " and " & SaltWeight & "g "& SaltName & return after field "v"
put " in ~" & V*0.8 & " ml double distilled water." & return & return after field "v"
end if
put "2. Titrate to pH " & LabpH & " with monobasic acid or alkali." & return & return after field "v"
put "3. Make up to " & V & "mls" & return after field "v"
put "" & return after field "v"
end if
end if
end mouseUp
-- part 19 (button)
-- low flags: 80
-- high flags: 8003
-- rect: left=272 top=295 right=316 bottom=372
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Save to disk
----- HyperTalk script -----
Global ShortName
on mouseUp
put word 3 of line 7 of field "BufferInfo" & "/pH=" & field "pH" & "/I=" & field "I" & "/T=" & field "T" into filename
ask "What filename for this buffer?" with filename
if it is empty then exit mouseUp
put it into filename
open file filename
write "=======================================" & field "Name" & space & field "pH" & return to file filename
write return to file filename
write field "v" to file filename
write return to file filename
write "=======================================" to file filename
close file filename
answer "On disk as: " & filename
end mouseUp
-- part 27 (button)
-- low flags: 80
-- high flags: 8003
-- rect: left=377 top=295 right=316 bottom=445
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: OK
----- HyperTalk script -----
on mouseUp
hide field "v"
show background button "Recipe"
hide background button "OK"
show background button "Next"
show background button "Help!"
show background button "Previous"
hide background button "Save to disk"
show background button "Tutorial"
show background button "Edit buffers"
end mouseUp
-- part 58 (button)
-- low flags: 00
-- high flags: A006
-- rect: left=391 top=141 right=162 bottom=479
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Other salt
----- HyperTalk script -----
on mouseUp
set the highlight of background button "Other salt" to true
set the highlight of background button "KCl" to false
set the highlight of background button "NaCl" to false
set the highlight of background button "Na2SO4" to false
end mouseUp
-- part 59 (field)
-- low flags: 00
-- high flags: 2002
-- rect: left=398 top=251 right=271 bottom=448
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 21
-- text size: 12
-- style flags: 0
-- line height: 12
-- part name: LabT
-- part 10 (field)
-- low flags: 80
-- high flags: 2007
-- rect: left=13 top=38 right=293 bottom=489
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 0
-- font id: 22
-- text size: 10
-- style flags: 0
-- line height: 13
-- part name: v
-- part 60 (button)
-- low flags: 00
-- high flags: A003
-- rect: left=52 top=296 right=316 bottom=119
-- title width / last selected line: 0
-- icon id / first selected line: 0 / 0
-- text alignment: 1
-- font id: 0
-- text size: 12
-- style flags: 0
-- line height: 16
-- part name: Help!
----- HyperTalk script -----
on mouseUp
set the visible of background field "helptext" to not the visible of background field "helptext"